<!-- @format -->

<template>
	<a-tag style="margin-left: 2%" size="medium" color="gray">
		<template #icon>
			<icon-storage />
		</template>
		订单号 : {{ orderInfo?.order_no }}
	</a-tag>
	<a-tag style="margin-left: 1%" size="medium" color="gray">
		<template #icon>
			<icon-user />
		</template>
		客户 : {{ orderInfo?.user?.username }}
	</a-tag>
	<a-tag style="margin-left: 1%" size="medium" color="gray">
		<template #icon>
			<icon-history />
		</template>
		下单时间 : {{ orderInfo?.created_at }}
	</a-tag>
	<div class="ma-content-block lg:flex justify-between p-4">
		<ma-crud :options="options" :columns="columns" ref="crudRef">
			<template #warehouse_id="{ record }">
				<a-tag color="blue">{{ record?.warehouse?.name }}</a-tag>
			</template>
			<template #summaryCell="{ column, record, rowIndex }">
				{{
					column.dataIndex == "warehouse_id" ? "合计" : column.dataIndex == "pick_weight" ? (record[column.dataIndex] - 0).toFixed(3) : record[column.dataIndex]
				}}
			</template>
		</ma-crud>
	</div>
</template>
<script setup>
	import { ref, reactive } from "vue";
	import warehouseOrderRecord from "@/api/warehouse/warehouseOrderRecord";
	import { Message } from "@arco-design/web-vue";
	import tool from "@/utils/tool";
	import * as common from "@/utils/common";

	const crudRef = ref();
	const warehouse_id = ref();
	const orderInfo = ref({});

	const open = (row) => {
		warehouse_id.value = row.id;
		orderInfo.value = row;
    crudRef.value.crudSearchRef.resetSearch();
		crudRef.value.requestData();
	};

	const numberOperation = (newValue, id, numberName) => {
		warehouseOrderRecord
			.numberOperation({ id, numberName, numberValue: newValue })
			.then((res) => {
				res.success && Message.success(res.message);
			})
			.catch((e) => {
				console.log(e);
			});
	};

	const switchStatus = (statusValue, id, statusName) => {
		warehouseOrderRecord
			.changeStatus({ id, statusName, statusValue })
			.then((res) => {
				res.success && Message.success(res.message);
			})
			.catch((e) => {
				console.log(e);
			});
	};

	const options = reactive({
		id: "flyos_warehouse_order_record",
		// rowSelection: {
		//   showCheckedAll: false
		// },
		pk: "id",
		bordered: { cell: true },
		showTools: false,
		showIndex: false,
		expandSearch: false,
		operationColumn: false,
		operationWidth: 160,
		showSummary: true,
		summary: [
			{
				dataIndex: "pick_number",
				action: "sum",
			},
			{
				dataIndex: "pick_weight",
				action: "sum",
			},
		],
		formOption: {
			viewType: "modal",
			width: 600,
		},
		api: warehouseOrderRecord.getList,
		recycleApi: warehouseOrderRecord.getRecycleList,
		add: {
			show: false,
			api: warehouseOrderRecord.save,
			auth: ["warehouse:orderRecord:save"],
		},
		edit: {
			show: false,
			api: warehouseOrderRecord.update,
			auth: ["warehouse:orderRecord:update"],
		},
		delete: {
			show: false,
			api: warehouseOrderRecord.deletes,
			auth: ["warehouse:orderRecord:delete"],
			realApi: warehouseOrderRecord.realDeletes,
			realAuth: ["warehouse:orderRecord:realDeletes"],
		},
		recovery: {
			show: false,
			api: warehouseOrderRecord.recoverys,
			auth: ["warehouse:orderRecord:recovery"],
		},
		import: {
			show: false,
			url: "warehouse/orderRecord/import",
			templateUrl: "warehouse/orderRecord/downloadTemplate",
			auth: ["warehouse:orderRecord:import"],
		},
		export: {
			show: true,
			url: "warehouse/orderRecord/export",
			auth: ["warehouse:orderRecord:export"],
		},
		beforeRequest: (params) => {
			params.warehouse_order_id = warehouse_id.value;
			params.order = "created_at";
			params.orderType = "desc";
		},
		afterRequest: (params) => {
			params.map((v, i) => {
				v.pick_weight = (v.pick_weight - 0).toFixed(3)
			});
		},
	});

	const columns = reactive([
		{
			title: "ID",
			dataIndex: "id",
			formType: "input",
			addDisplay: false,
			editDisplay: false,
			hide: true,
			commonRules: {
				required: true,
				message: "请输入ID",
			},
		},
		// {
		//   title: "订单ID",
		//   dataIndex: "warehouse_order_id",
		//   formType: "input",
		//   search: true,
		//   commonRules: {
		//     required: true,
		//     message: "请输入订单ID"
		//   }
		// },
		{
			title: "订单号",
			dataIndex: "warehouse_order_id",
			align: "center",
			formType: "select",
			hide: true,
			dict: {
				// 远程通用接口请求，新版代码生成都有一个 remote 接口
				remote: "warehouse/order/remote",
				// 指定组件接收的props
				props: { label: "order_no", value: "id" },
				// 开启分页
				openPage: true,
				// 远程请求配置项
				remoteOption: {
					// 按用户名排序
					sort: { id: "desc" }, // 如果不指定排序方式，默认为正序排序
					// 设置查询的字段
					select: ["id", "order_no"],
					// 设置数据过滤
					filter: {},
					// 关联模型
					relations: [],
				},
			},
		},
		{
			title: "客户姓名",
			dataIndex: "user_id",
			align: "center",
			formType: "select",
			hide: true,
			dict: {
				// 远程通用接口请求，新版代码生成都有一个 remote 接口
				remote: "system/user/remote",
				// 指定组件接收的props
				props: { label: "username", value: "id" },
				// 开启分页
				openPage: true,
				// 远程请求配置项
				remoteOption: {
					// 按用户名排序
					sort: { username: "desc" }, // 如果不指定排序方式，默认为正序排序
					// 设置查询的字段
					select: ["id", "username"],
					// 设置数据过滤
					filter: {},
					// 关联模型
					relations: [],
				},
			},
		},
		{
			title: "车号",
			dataIndex: "prediction.car_no",
			align:'center',
			formType: "input",
			addDisplay: false,
			editDisplay: false,
			search: false,
		},
		{
			title: "存放仓库",
			dataIndex: "warehouse_id",
			align: "center",
			formType: "select",
			dict: {
				// 远程通用接口请求，新版代码生成都有一个 remote 接口
				remote: "warehouse/master/remote",
				// 指定组件接收的props
				props: { label: "name", value: "id" },
				// 开启分页
				openPage: true,
				// 远程请求配置项
				remoteOption: {
					// 按用户名排序
					sort: { id: "desc" }, // 如果不指定排序方式，默认为正序排序
					// 设置查询的字段
					select: ["id", "name"],
					// 设置数据过滤
					filter: {},
					// 关联模型
					relations: [],
				},
			},
		},
		{
			title: "品名",
			dataIndex: "prediction.goods_name",
			align: "center",
			formType: "input",
			addDisplay: false,
			editDisplay: false,
			search: false,
		},
		// {
		//   title: "仓位ID",
		//   dataIndex: "warehouse_childs_id",
		//   formType: "input",
		//   search: true,
		//   commonRules: {
		//     required: true,
		//     message: "请输入仓位ID"
		//   }
		// },
		{
			title: "仓位（横）",
			dataIndex: "horizontal_position",
			align: "center",
			formType: "input",
			search: true,
		},
		{
			title: "仓位（纵）",
			dataIndex: "release_position",
			align: "center",
			formType: "input",
			search: true,
		},
		{
			title: "仓位（层）",
			dataIndex: "reaches_position",
			align: "center",
			formType: "input",
			search: true,
		},
		{
			title: "托管状态",
			dataIndex: "status",
			formType: "select",
			align: "center",
			search: true,
			dict: {
				data: [
					{
						label: "免费托管",
						value: "1",
					},
					{
						label: "收费托管",
						value: "2",
					},
				],
				translation: true,
				tagColors: { 1: "blue", 2: "red" },
			},
		},
		{
			title: "出库状态",
			dataIndex: "chuku_status",
			align: "center",
			formType: "select",
			search: true,
			dict: {
				data: [
					{
						label: "待出库",
						value: "1",
					},
					{
						label: "部分出库",
						value: "2",
					},
					{
						label: "已完成",
						value: "3",
					},
				],
				translation: true,
				tagColors: { 1: "grey", 2: "red", 3: "green" },
			},
		},
		
		{
			title: "箱号",
			dataIndex: "prediction.box",
			align: "center",
			formType: "input",
			addDisplay: false,
			editDisplay: false,
		},
		{
			title: "箱型箱类",
			dataIndex: "prediction.box_type",
			align: "center",
			formType: "input",
			addDisplay: false,
			editDisplay: false,
		},
		{
			title: "箱属",
			dataIndex: "prediction.box_belong",
			align: "center",
			formType: "input",
			addDisplay: false,
			editDisplay: false,
		},
		{
			title: "提货数量（件）",
			dataIndex: "pick_number",
			align: "center",
			formType: "input",
		},
		{
			title: "提货（吨）",
			dataIndex: "pick_weight",
			align: "center",
			formType: "input",
		},
		// {
		//   title: "收货人",
		//   dataIndex: "receiver",
		//   formType: "input"
		// },
		// {
		//   title: "收货手机",
		//   dataIndex: "receiver_mobile",
		//   formType: "input"
		// },
		// {
		//   title: "收货电话",
		//   dataIndex: "receiver_tel",
		//   formType: "input"
		// },
		// {
		//   title: "区域",
		//   dataIndex: "area",
		//   formType: "input"
		// },
		// {
		//   title: "创建时间",
		//   dataIndex: "created_at",
		//   align:'center',
		//   formType: "range",
		//   search: true,
		//   addDisplay: false,
		//   editDisplay: false,
		//   showTime: true
		// },
		{
			title: "修改时间",
			dataIndex: "updated_at",
			formType: "date",
			addDisplay: false,
			editDisplay: false,
			hide: true,
			showTime: true,
		},
		{
			title: "删除时间",
			dataIndex: "deleted_at",
			formType: "date",
			addDisplay: false,
			editDisplay: false,
			hide: true,
			showTime: true,
		},
		{
			title: "创建者",
			dataIndex: "created_by",
			formType: "input",
			addDisplay: false,
			editDisplay: false,
			hide: true,
		},
		{
			title: "更新者",
			dataIndex: "updated_by",
			formType: "input",
			addDisplay: false,
			editDisplay: false,
			hide: true,
		},
	]);
	defineExpose({ open });
</script>
<script>
	export default { name: "warehouse:orderRecord" };
</script>
